package test01;

import mapper.StudentMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;
import pojo.Student;

import java.io.IOException;
import java.io.Reader;

/**
 * @ClassName Demo
 * @Description TODO
 * @Author 耀酱
 * @Date 2023/6/8 19:43
 * @Version 1.0
 */

public class Demo {

    @Test
    public void test01() throws IOException {
        Reader resources = Resources.getResourceAsReader("Mybatis.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resources);

        Configuration configuration = sqlSessionFactory.getConfiguration();
        System.out.println(configuration);

        try(SqlSession sqlSession = sqlSessionFactory.openSession()){

            StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
            for (Student student : mapper.selectAllStudent()) {
                System.out.println(student);
            }


        }catch (Exception e){

        }

    }
}
